package com.flyone.fuxiao.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * @program: text-to-picture
 * @ClassName: Result
 * @description: 后端返回结果方式二
 * @author: banyun
 * @create: 2024-03-16 12:54
 */
@ApiModel("通用返回结果")
@Data
public class Result<T> implements Serializable {

    @ApiModelProperty("编码：1成功，0和其它数字为失败")
    private Integer code;
    //编码：1成功，0和其它数字为失败
    @ApiModelProperty("错误信息")
    private String msg;
    //错误信息
    @ApiModelProperty("数据")
    private T data;
    //数据

    public static <T> Result<T> success() {
        Result<T> result = new Result<T>();
        result.code = 1;
        return result;
    }

    public static <T> Result<T> success(T object) {
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = 1;
        return result;
    }

    public static <T> Result<T> error(String msg) {
        Result result = new Result();
        result.msg = msg;
        result.code = 0;
        return result;
    }

}

